<template>
    <view>
        <!-- 轮播图 -->
        <view class="banner">
            <swiper class="swiper-banner" previous-margin="0rpx" indicator-dots="true" indicator-color="#767574"
                indicator-active-color="#D8D8D8" :autoplay="true" :interval="3000" :duration="400">
                <swiper-item v-for="m in bannerList" :key="m.id">
                    <view class="swiper-item">
                        <image class="img" :src="m.pic" mode="widthFix"></image>
                    </view>
                </swiper-item>
            </swiper>
        </view>
        <u-line dashed style="margin: 20rpx 0"></u-line>
        <!-- 分隔区的渲染 -->
        <view class="section-header">
            <view class="head-left">
                推荐博文
            </view>
        </view>
        <!-- 博客文章列表 -->
        <u-line dashed style="margin: 20rpx 0"></u-line>
        <!-- 博客文章列表 -->
        <view class="content">
            <view class="section-list">
                <view class="section-item" v-for="item in saleMostProducts" :key="item.Id" @click="goPostDetail(item)">
                    <view class='list-logo'>
                        <image :src='cover_img' style="width: 100%;height: 100%" mode='scaleToFill'></image>
                    </view>
                    <view class="list-desc">
                        <view class="desc-title">
                            <text class="isTop">{{item.title}}</text>
                        </view>
                        <view class="desc-com">
                            简介：{{item.summary}}
                        </view>
                        <view class="desc-time">
                            <u-icon name="clock" size="12"></u-icon>
                            <text class="time">{{item.pub_date}}</text>
                            <text style="color: brown;padding-left: 30px;">类别：{{item.cate_name}}</text>
                        </view>
                    </view>
                </view>
                <u-divider text="END"></u-divider>
            </view>
        </view>
    </view>
</template>

<script>
    import {
        bannerList,
        saleMostProducts
    } from '@/api/index/index.js';

    export default {
        data() {
            return {
                cover_img: '../../static/imgs/sample2.jpg',
                bannerList: [],
                saleMostProducts: [],
            }
        },
        onPullDownRefresh() {
            this.init();
        },
        methods: {
            goPostDetail(row) {
                if (!uni.getStorageSync('token')) {
                    uni.showToast({
                        icon: 'none',
                        position: 'bottom',
                        title: '登录才有权限看'
                    });
                    setTimeout(() => {
                        uni.navigateTo({
                            url: '/pages/user/login/login'
                        })
                    }, 1000)
                } else {
                    uni.navigateTo({
                        url: '/pages/index/articleInfo/articleInfo?Id=' + row.Id
                    });
                }
            },
            async init() {
                // 轮播数据
                this.bannerList = (await bannerList()).data.items;
                // 博客列表数据
                this.saleMostProducts = (await saleMostProducts()).data.items;
                console.log()
                uni.stopPullDownRefresh()
            },
        },
        onLoad() {
            this.init();
        }
    }
</script>

<style lang="scss" scoped>
    .content {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
    }

    // 轮播图样式
    .banner {
        .swiper-banner {
            width: 100%;
            height: 362rpx;

            .swiper-item {
                width: 750rpx;
                height: 100%;
                border-radius: 0 0 30rpx 30rpx;
                overflow: hidden;

                .img {
                    width: 100%;
                    height: 100%;
                }
            }
        }
    }

    // 分割区的样式
    .section-header {
        display: flex;
        justify-content: space-between;
        align-content: center;
        width: 100%;
        padding: 0 25rpx;

        .head-left {
            position: relative;
            padding-left: 20rpx;
            font-weight: bold;

            &:before {
                content: '';
                position: absolute;
                left: 0rpx;
                top: 0rpx;
                width: 10rpx;
                height: 100%;
                border-radius: 5rpx;
                background-color: #d81e06;
            }
        }
    }

    //博客列表样式
    .section {
        width: 700rpx;
        margin: 0rpx auto;
        box-sizing: border-box;
        background-color: #fff;
        border-radius: 10rpx;

        &-quick {
            height: 250rpx;
            padding: 20rpx;

            .quick-top {
                padding-bottom: 20rpx;

                .quick-logo {
                    width: 80rpx;
                    height: 80rpx;
                    margin-bottom: 8rpx;
                }

                .grid-text {
                    font-size: 22rpx;
                    color: #555454;
                    text-align: center;
                }
            }

            .quick-bottom {
                display: flex;
                justify-content: center;
                align-content: center;

                .bot-right {
                    width: 100%;
                    padding-top: 10rpx;
                }
            }

        }

        &-list {
            .section-item {
                width: 700rpx;
                margin-bottom: 20rpx;
                box-sizing: border-box;
                background-color: #fff;
                border-radius: 10rpx;
                height: 200rpx;
                padding: 20rpx;
                display: flex;
                justify-content: flex-start;
                align-content: center;

                .list-logo {
                    width: 150rpx;
                    height: 150rpx;
                    overflow: hidden;
                    display: flex;
                    justify-content: center;
                    align-content: center;
                    border-radius: 50%;
                    box-sizing: 0rpx 0rpx 10rpx #636363;
                    border: 1rpx solid #eee;
                }

                .list-desc {
                    width: calc(100% - 150rpx);
                    padding-left: 20rpx;
                    font-family: 'monaco', 'Consolas', "Liberation Mono", Courier, monospace;

                    .desc-title {
                        font-weight: bold;
                        font-size: 18px;
                        padding-bottom: 14rpx;
                        overflow: hidden;
                        text-overflow: ellipsis;
                        white-space: nowrap;

                        .isTop {
                            color: #fff;
                            text-shadow: 0rpx 5rpx 15rpx #dec1c1;
                            background-color: #d81e06;
                            padding: 5rpx 8rpx;
                            border-radius: 8rpx;
                            margin-right: 5rpx;
                            font-size: 22rpx;
                        }
                    }

                    .desc-com {
                        font-size: 12px;
                        line-height: 30rpx;
                        text-indent: 0.5rem;
                        height: 60rpx;
                        overflow: hidden;
                        display: -webkit-box;
                        -webkit-box-orient: vertical;
                        -webkit-line-clamp: 2;
                        color: #999;
                    }

                    .desc-time {
                        padding-top: 15rpx;
                        color: #999;
                        font-size: 12px;
                        display: flex;
                        justify-content: flex-start;
                        align-content: center;

                        .time {
                            padding-left: 8rpx;
                        }
                    }
                }

            }
        }
    }

    .slogan {
        padding: 30rpx;
        position: relative;
        font-family: -apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Oxygen, Ubuntu, Cantarell, Fira Sans, Droid Sans, Helvetica Neue, sans-serif;
        color: #908f8f;

        &:before {
            content: '';
            position: absolute;
            left: 0rpx;
            top: 0rpx;
            width: 10rpx;
            height: 100%;
            border-bottom-left-radius: 10rpx;
            border-top-left-radius: 10rpx;
            background-color: #d81e06;

        }
    }
</style>
